export * from "./login/index";
export * from "./order/index";
export * from "./register/index";
export * from "./user/index";
import { request } from "@/utils/request";

export const getUploadFileToken = async (data: any) => {
  const response = await request("/v1/admin/us3/upload_file_token", {
    method: "POST",
    body: JSON.stringify(data),
  });
  return response;
};

export const uploadFile = async (
  file: any,
  key: any,
  authorization: any,
  content_type: any,
): Promise<any> => {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onload = async () => {
      const result = reader.result;
      fetch(`${import.meta.env.VITE_APP_UPLOAD_URL}` + "/" + encodeURIComponent(key), {
        method: "PUT",
        body: result,
        headers: {
          Authorization: authorization,
          "Content-Type": content_type,
        },
      })
        .then(resolve)
        .catch(reject);
    };
    reader.onerror = reject;
    reader.readAsArrayBuffer(file);
  });
};
